Welcome Guest | Sign in | Register

Home > C Programming > Inbuilt Functions > Questions and Answers

01. With what do you replace the ???? to make the function shown below return the correct answer?
long factorial (long x)
{
????
return x * factorial(x - 1);
}
A. if (x == 0) return 0; B. return 1;
C. if (x >= 2) return 2; D. if (x <= 1) return 1;

Answer and Explanation

Answer: if (x <= 1) return 1;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What will be the value of `a` after the following code is executed?
#define square(x) x*x
a = square(2+3)
A. 25 B. 13
C. 11 D. 10

Answer and Explanation

Answer: 11

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What would be the output of the following program?
#include
main()
{
char str[]="S\065AB";
printf("\n%d", sizeof(str));
}
A. 7 B. 6
C. 5 D. error

Answer and Explanation

Answer: 6

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What will be the output of following statements?

char x[ ] = "hello hi"; printf("%d%d",sizeof(*x),sizeof(x));
A. 88 B. 18
C. 29 D. 19

Answer and Explanation

Answer: 19

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What will be the output of following C code?
#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
A. 16 B. 64
C. 42 D. 4

Answer and Explanation

Answer: 64

Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What will be the output of following C code?
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
A. Linker error B. Compiler error
C. 20 D. 0

Answer and Explanation

Answer: Linker error

Explanation:
extern declaration specifies that the variable i is defined somewhere else. The compiler passes the external variable to be resolved by the linker. So compiler doesn't find an error. During linking the linker searches for the definition of i. Since it is not found the linker shows an error.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What will be the output of following C code?
void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
A. 5.2 B. 2.5
C. 7 D. 8

Answer and Explanation

Answer: 7

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What will be the output of following C code?

main()
{
while (strcmp(“some”,”some\0”))
printf(“Strings are not equal\n”);
}
A. No output B. Error
C. Compiler Error D. Strings are not equal

Answer and Explanation

Answer: No output

Explanation:
Ending the string constant with \0 explicitly makes no difference. So “some” and “some\0” are equivalent. So, strcmp returns 0 (false) hence breaking out of the while loop.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. What will be the output of following C code?
void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));
printf(“%d”,*mptr);
int *cptr = (int*)calloc(sizeof(int),1);
printf(“%d”,*cptr);
}
A. 1 B. Garbage-value 0
C. Error D. None of these

Answer and Explanation

Answer: Garbage-value 0

Explanation:
The memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. What is the output of following program?
void main(){
printf("%d%d",sizeof(10),sizeof(5,5));
}
A. 2 2 B. 2 4
C. 2 6 D. 2 8

Answer and Explanation

Answer: 2 8

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.